// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.erosion.obj;

import java.util.ArrayList;
import zombie.iso.IsoObject;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteInstance;

public final class ErosionObjOverlay {
    private final ErosionObjOverlaySprites sprites;
    public String name;
    public int stages;
    public boolean applyAlpha;
    public int cycleTime;

    public ErosionObjOverlay(ErosionObjOverlaySprites _sprites, int _cycleTime, boolean _applyAlpha) {
        this.sprites = _sprites;
        this.name = _sprites.name;
        this.stages = _sprites.stages;
        this.applyAlpha = _applyAlpha;
        this.cycleTime = _cycleTime;
    }

    public int setOverlay(IsoObject _obj, int _curID, int _stage, int _season, float _alpha) {
        if (_stage >= 0 && _stage < this.stages && _obj != null) {
            if (_curID >= 0) {
                this.removeOverlay(_obj, _curID);
            }

            IsoSprite isoSprite = this.sprites.getSprite(_stage, _season);
            IsoSpriteInstance isoSpriteInstance = isoSprite.newInstance();
            if (_obj.AttachedAnimSprite == null) {
                _obj.AttachedAnimSprite = new ArrayList();
            }

            _obj.AttachedAnimSprite.add(isoSpriteInstance);
            return isoSpriteInstance.getID();
        } else {
            return -1;
        }
    }

    public boolean removeOverlay(IsoObject _obj, int _id) {
        if (_obj == null) {
            return false;
        } else {
            ArrayList arrayList = _obj.AttachedAnimSprite;
            if (arrayList != null && !arrayList.isEmpty()) {
                for (int int0 = 0; int0 < _obj.AttachedAnimSprite.size(); int0++) {
                    if (((IsoSpriteInstance)_obj.AttachedAnimSprite.get(int0)).parentSprite.ID == _id) {
                        _obj.AttachedAnimSprite.remove(int0--);
                    }
                }

                for (int int1 = arrayList.size() - 1; int1 >= 0; int1--) {
                    if (((IsoSpriteInstance)arrayList.get(int1)).getID() == _id) {
                        arrayList.remove(int1);
                        return true;
                    }
                }

                return false;
            } else {
                return false;
            }
        }
    }
}
